<?php

/**
 * iWebkit for MyBB, provide a mobile friendly interface.
 * Copyright (C) 2010  Christopher John Jackson
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB")) {
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("index_start", "iwebkit_indexcheck");
$plugins->add_hook("showthread_start", "iwebkit_checkAtThread");
$plugins->add_hook("forumdisplay_start", "iwebkit_checkAtForum");

function iwebkit_info() {
    return array(
            "name"			=> "iWebkit for MyBB",
            "description"	=> "Add iWebkit interface to MyBB",
            "website"		=> "http://cj-jackson.com/",
            "author"		=> "Christopher John Jackson",
            "authorsite"	=> "http://cj-jackson.com/",
            "version"		=> "0.3 alpha",
            "guid"			=> "",
            "compatibility" => "*",
    );
}

function iwebkit_activate() {
}

function iwebkit_deactivate() {
}

function iwebkit_indexcheck() {
    if(preg_match('#((webOS|SymbianOS|Nokia)+?AppleWebKit|AppleWebKit(.*?)Mobile)#',$_SERVER['HTTP_USER_AGENT'])) {
        header("Location: /iphone/");
    }
}

function iwebkit_checkAtThread() {
    global $tid;
    if(preg_match('#((webOS|SymbianOS|Nokia)+?AppleWebKit|AppleWebKit(.*?)Mobile)#',$_SERVER['HTTP_USER_AGENT'])) {
        header("Location: /iphone/index.php/thread-".$tid.".html");
    }
}

function iwebkit_checkAtForum() {
    global $mybb;
    $fid = $mybb->input['fid'];
    if(preg_match('#((webOS|SymbianOS|Nokia)+?AppleWebKit|AppleWebKit(.*?)Mobile)#',$_SERVER['HTTP_USER_AGENT'])) {
        header("Location: /iphone/index.php/forum-".$fid.".html");
    }
}

?>